<?php
defined('SWAP_ROOT') or die('非法操作');
function cd_email_reg_read() {
    import("swap.Mail");

}
function cd_email_reg_randStr($len = 6) {
    $chars = '123456789QWERTYUIOPASDFGHJKLZXCVBNM';
    mt_srand((double)microtime()*1000000*getmypid());
    $password = '';
    while (strlen($password) < $len)
        $password.= substr($chars,(mt_rand()%strlen($chars)),1);
    return $password;
}
class cd_email_reg extends controller
{
    function config() {
        return array(
            'swap_no_login' => array(
                'index' => '1'
            ),
            'index' => '0'
        );
    }
    function index() {
    $nbip = $_SERVER["REMOTE_ADDR"];
            $REG_CODE_PD = _GET('reg_cc_pd');
            if(!empty($REG_CODE_PD)){
                $REG_CODE_email = _GET('email');
                if(!empty($REG_CODE_email)){
                    if (!$this->IsMail($REG_CODE_email)) {
                    exit('1');
                    }else{
                        $this->conn->select('插件配置', "插件名称='reg_ccdalao_code'", "值='".$nbip."'");
                        if ($this->conn->db_num_rows() != 0) {
                            exit('2');
                        }else{
                            $code = cd_email_reg_randStr();
                            cd_email_reg_read();
                            plug_eva('reg_ccdalao_code','邮件码:'.$code,$nbip);
                            $lang['标题']='注册验证码';
                            $lang['内容']='您的验证码是:{<code>}';
                            $lang['发信人']='注册验证码';
                            $array['电子邮件'] = $REG_CODE_email;
                            $lang['内容'] = str_replace('{<code>}',$code,$lang['内容']);
                            SendMail($array['电子邮件'],$lang['标题'],$lang['内容'],$lang['发信人']);
                            exit('3');
                        }
                        
                    }
                    
                }else{
                    exit('4');
                }
            
            }
    
    }


}
?>